package com.zb.uniman.job;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Author:B
 * Description:
 */
@Slf4j
@Component
public class cachejob {
    //每过一分钟执行一次，在下一分钟的01秒开始执行
    @Scheduled(cron = "1 1/1 * * * * ")
    public void executejob() {
        long l = System.currentTimeMillis();
        Date date = new Date(l);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
        String s = dateFormat.format(date);
        log.info(s);
    }

    @Autowired
    private RedisTemplate redisTemplate;

    private String rediskey = "Uniman:user:redis:userid:";

    @Scheduled(cron = "1 1/1 * * * * ")
    public void setredis() {
        Thread.currentThread().getName();

        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(rediskey+System.currentTimeMillis(), Thread.currentThread().getName(), 1000 * 60, TimeUnit.MILLISECONDS);
        Object o = valueOperations.get(rediskey+System.currentTimeMillis());
//        System.out.println(o);
    }

}
